﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QuanLyCayXanh.Models;
using System.Data;

namespace QuanLyCayXanh.Controllers
{
    public class GroupOfTreeController : Controller
    {
        private QuanLyCayXanhContext db = new QuanLyCayXanhContext();
        //
        // GET: /GroupOfTree/

        public ActionResult Index()
        {
            return View(db.GroupOfTrees.ToList());
        }

        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(GroupOfTree groupOfTree)
        {
            if (ModelState.IsValid)
            {
                db.GroupOfTrees.Add(groupOfTree);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(groupOfTree);
        }

        public ActionResult Edit(int id = 0)
        {
            GroupOfTree groupOfTree = db.GroupOfTrees.Find(id);
            if (groupOfTree == null)
                return HttpNotFound();
            return View(groupOfTree);
            

        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(GroupOfTree groupOfTree)
        {
            if (ModelState.IsValid)
            {
                db.Entry(groupOfTree).State = EntityState.Modified;
                db.SaveChanges();                
                return RedirectToAction("Index");
            }            
            return View(groupOfTree);
        }

        public ActionResult Details(int id = 0)
        {
            GroupOfTree groupOfTree = db.GroupOfTrees.Find(id);
            if (groupOfTree == null)
                return HttpNotFound();
            return PartialView(groupOfTree);
        }

        [HttpPost,ActionName("Delete")]              
        public ActionResult DeleteConfirmed(int id)
        {
            GroupOfTree groupOfTree = db.GroupOfTrees.Find(id);
            db.GroupOfTrees.Remove(groupOfTree);
            db.SaveChanges();
            return Content(Boolean.TrueString);
        }
    }
}
